//统一管理咱们项目用户相关的接口
import request from '@/utils/request'
import type {
  loginFormData,
  loginResponseData,
  RegisterFormData,
  userInfoResponseData,
  DeleteRequest,
  UserAddRequest,
  UserQueryRequest,
  UserUpdateRequest,
  PageUser,
  SetRoleRequest,
} from './type'
//项目用户相关的请求地址
enum API {
  LOGIN_URL = '/user/login',
  USERINFO_URL = '/user/get/login',
  USER_REGISTER_URL = '/user/register',
  LOGOUT_URL = '/user/logout',
  LIST_URL = '/admin/user/list',
  DELETE_URL = '/admin/user/delete',
  ADD_URL = '/admin/user/add',
  UPDATE_URL = '/admin/user/update',
  DELETE_BATCH_URL = '/admin/user/deleteBatch',
  GET_ROLE_URL = '/role/getRole',
  SET_ROLE_URL = '/user/set',
}

//登录接口
export const reqLogin = (data: loginFormData) =>
  request.post<any, loginResponseData>(API.LOGIN_URL, data)

//注册接口
export const reqRegister = (data: RegisterFormData) =>
  request.post<any, any>(API.USER_REGISTER_URL, data)

//获取用户信息
export const reqUserInfo = () =>
  request.get<any, userInfoResponseData>(API.USERINFO_URL)

//退出登录
export const reqLogout = () => request.post<any, any>(API.LOGOUT_URL)

//获取标签列表接口
export const reqList = (data: UserQueryRequest) =>
  request.post<any, PageUser>(API.LIST_URL, data)

//删除标签接口
export const reqDelete = (data: DeleteRequest) =>
  request.post<any, any>(API.DELETE_URL, data)

//新增标签接口
export const reqAdd = (data: UserAddRequest) =>
  request.post<any, any>(API.ADD_URL, data)

//修改标签接口
export const reqUpdate = (data: UserUpdateRequest) =>
  request.post<any, any>(API.UPDATE_URL, data)

export const reqDeleteBatch = (ids: any) =>
  request.post<any, any>(API.DELETE_BATCH_URL, { ids: ids })

//获取角色ID
export const reqGetRoleId = (userId: number) =>
  request.get<any, any>(API.GET_ROLE_URL, { params: { userId } })

//分配角色接口
export const reqSetRole = (data: SetRoleRequest) =>
  request.post<any, any>(API.SET_ROLE_URL, data)
